package com.example.chao.myphotosearch.view.activities;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.chao.myphotosearch.R;
import com.example.chao.myphotosearch.adapters.LargeImgPagerAdapter;
import com.example.chao.myphotosearch.bean.SosoImage;
import com.example.chao.myphotosearch.model.SqlModel;
import com.example.chao.myphotosearch.widget.ImageViewPager;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chao on 2016/4/11.
 */
public class ShowLargeImgActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
    @Bind(R.id.large_viewPager)
    ImageViewPager largeViewPager;
    @Bind(R.id.large_page)
    TextView largePage;
    @Bind(R.id.large_RL)
    RelativeLayout largeRL;
    @Bind(R.id.large_img_download)
    ImageView largeImgDownload;
    @Bind(R.id.large_img_qq_share)
    ImageView largeImgQqShare;
    @Bind(R.id.large_img_weixin_share)
    ImageView largeImgWeixinShare;
    @Bind(R.id.large_img_sina_share)
    ImageView largeImgSinaShare;
    private ArrayList<SosoImage> sosoImages;
    private int currentPosition;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_large_img);
        ButterKnife.bind(this);
        initData();
        largeViewPager.setAdapter(new LargeImgPagerAdapter(sosoImages));
        largeViewPager.setCurrentItem(currentPosition);
        largeViewPager.addOnPageChangeListener(this);
    }



    @OnClick(R.id.large_RL)
    public void onLargeLLClicked(View view) {
        onBackPressed();
    }
    @OnClick(R.id.large_img_download)
    public void onDownLoadClicked(View view){
            SosoImage sosoImage = sosoImages.get(currentPosition);
            if(sosoImages!=null) {
                SqlModel.getSaveBitmapObservable(this, sosoImage);
            }
        Log.e("large_img_download","onDownLoadClicked");
    }
    @OnClick(R.id.large_img_qq_share)
    public void onQQShareClicked(View view){
        Log.e("large_img_qq_share", "onQQShareClicked");
    }
    @OnClick(R.id.large_img_weixin_share)
    public void onWeiXinShareClicked(View view){
        Log.e("large_img_weixin_share", "onWeiXinShareClicked");
    }
    @OnClick(R.id.large_img_sina_share)
    public void onSinaShareClicked(View view){
        Log.e("large_img_sina_share","onSinaShareClicked");
    }



    public void initData() {
        currentPosition = getIntent().getIntExtra("position", 0);
        sosoImages = (ArrayList<SosoImage>) getIntent().getSerializableExtra("netImages");
        largePage.setText((currentPosition + 1) + "/" + sosoImages.size());
    }

    @Override
    public void onBackPressed() {
        setResult(100, getIntent().putExtra("position", currentPosition));
        super.onBackPressed();
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        currentPosition = position;
        largePage.setText((position + 1) + "/" + sosoImages.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
